//
//  TSTools.m
//  chart
//
//  Created by xu on 15/7/21.
//  Copyright (c) 2015年 xu. All rights reserved.
//

#import "TSTools.h"

@implementation TSTools

#pragma mark - check String is Empty
+ (BOOL)isEmpty:(NSString *)string
{
    if (![string isKindOfClass:[NSString class]])
        string = [string description];
    if (string == nil || string == NULL)
        return YES;
    if ([string isKindOfClass:[NSNull class]])
        return YES;
    if ([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length]==0)
        return YES;
    if ([string isEqualToString:@"(null)"])
        return YES;
    if ([string isEqualToString:@"(null)(null)"])
        return YES;
    if ([string isEqualToString:@"<null>"])
        return YES;
    
    // return Default
    return NO;
}

+ (BOOL)isEmptyObject:(id)object
{
    if ([object isKindOfClass:[NSNull class]]) {
        return YES;
    }
    if (object == nil) {
        return YES;
    }
    if (object == [NSNull null]) {
        return YES;
    }
    
    return NO;
}

+ (void)showAlert:(NSString *)msg
{
    UIAlertView *alert_view = [[UIAlertView alloc] initWithTitle:nil message:msg delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert_view show];
}

/* 存取deviceToken(推送) */
+ (void)setDeviceToken:(NSData *)deviceToken
{
    if (deviceToken && deviceToken.length > 0) {
        [USERDEFAULTS setValue:deviceToken forKey:TSUserDefaultsKey_DeviceToken];
    }
}

+ (NSData *)getDeviceToken
{
    NSData *device_token_data = nil;
    if ([USERDEFAULTS objectForKey:TSUserDefaultsKey_DeviceToken]) {
        device_token_data = [USERDEFAULTS objectForKey:TSUserDefaultsKey_DeviceToken];
    }
    
    return device_token_data;
}

+ (NSString *)getReceiveStatusTypeString:(NSInteger)status
{
    switch (status) {
        case RECEIVE_STATUS_TYPE_DELETE:
            return @"删除";
        case RECEIVE_STATUS_TYPE_NOT_RED:
            return @"未读";
        case RECEIVE_STATUS_TYPE_CONFIRM:
            return @"确认";
        case RECEIVE_STATUS_TYPE_LEAVE:
            return @"请假";
        case RECEIVE_STATUS_TYPE_DELEGATE:
            return @"委托";
        case 4:
            return @"委托成功";
        case 5:
            return @"委托中";
        case 6:
            return @"委托成功";
        case 7:
            return @"确认委托";
        case 8:
            return @"委托取消";
        case 9:
            return @"已读";
        default:
            break;
    }
    
    return @"";
}

+ (NSString *)getSendStatusTypeString:(NSInteger)status
{
    switch (status) {
        case SEND_STATUS_TYPE_NOT_AUDIT:
            return @"未审核";
        case SEND_STATUS_TYPE_AUDITED:
            return @"已审核";
        case SEND_STATUS_TYPE_AUDIT_FAILURE:
            return @"审核未通过";
        case SEND_STATUS_TYPE_AUDIT_OUT_TIME:
            return @"超时未审核";
            
        default:
            break;
    }
    
    return @"";
}

+ (NSString *)getSendStatusTypeString2:(NSInteger)status del:(NSInteger)del
{
    
    if(status==-1){
        return @"未审核";
    }
    if(del==1){return @"审核未通过";}
        return @"已审核";
    
    return @"";
}

+ (NSString *)getJournalStatusTypeString:(NSInteger)status
{
    switch (status) {
        case JOURNAL_RUN_STATUS_PROGRESSING:
            return @"进行中";
        case JOURNAL_RUN_STATUS_COMPELETED:
            return @"完成";
            
        default:
            break;
    }
    
    return @"";
}

+ (NSString *)getStatisticStatusTypeString:(NSInteger)status
{
    switch (status) {
        case STATISTIC_STATUS_TYPE_DELETE:
            return @"删除";
        case STATISTIC_STATUS_TYPE_NOT_RED:
            return @"未读";
        case STATISTIC_STATUS_TYPE_CONFIRM:
            return @"确认";
        case STATISTIC_STATUS_TYPE_LEAVE:
            return @"请假";
        case STATISTIC_STATUS_TYPE_DELEGATING:
            return @"委托中";
        case STATISTIC_STATUS_TYPE_DELEGAE_SUCCESS:
            return @"委托成功";
        case STATISTIC_STATUS_TYPE_DELEGATING2:
            return @"委托中";
        case STATISTIC_STATUS_TYPE_DELEGATE_SUCCESS2:
            return @"委托成功";
        case STATISTIC_STATUS_TYPE_DELEGATE_CONFIRM:
            return @"确认委托";
        default:
            break;
    }
    
    return @"";
}

+ (NSString *)getDateByTime:(NSTimeInterval)time{
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:time];
    NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
    [dateformatter setDateFormat:@"YYYY-MM-dd HH:mm"];
    NSString *dateString = [dateformatter stringFromDate:date];
    
    return dateString;
}

+ (NSString *)getDateNoYearByTime:(NSTimeInterval)time{
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:time];
    NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
    [dateformatter setDateFormat:@"MM-dd HH:mm"];
    NSString *dateString = [dateformatter stringFromDate:date];
    
    return dateString;
}

+ (NSString *)getDateMonthDay:(NSTimeInterval)time{
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:time];
    NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
    [dateformatter setDateFormat:@"MM月dd日"];
    NSString *dateString = [dateformatter stringFromDate:date];
    
    return dateString;
}

+ (NSDate*)convertDateFromString:(NSString*)uiDate
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;
    [formatter setDateFormat:@"YYYY-MM-dd HH:mm"];
    NSDate *date=[formatter dateFromString:uiDate];
    return date;
}

+ (BOOL)validateMobile:(NSString *)mobile
{
    //手机号以13， 15，18开头，八个 \d 数字字符
    NSString *phoneRegex = @"^1((3|5|7|8)\\d)\\d{8}$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
    return [phoneTest evaluateWithObject:mobile];
}

+ (NSString *)getTaskStatus:(NSInteger)status
{
    switch (status) {
        case TASK_RUN_STATUS_NO_AUDIT:
            return @"未审核";
        case TASK_RUN_STATUS_COMMIT:
            return @"已提交";
        case TASK_RUN_STATUS_NO_PASS:
            return @"未通过";
        case TASK_RUN_STATUS_RUN:
            return @"进行中";
        case TASK_RUN_STATUS_NO_SEND:
            return @"未发送";
        default:
            break;
    }
    
    return @"";
}

+ (NSString *)getTaskType:(NSString *)type
{
    if( [type isEqualToString:@"不紧急不重要"]){
        return @"100";
    }else if( [type isEqualToString:@"不紧急重要"]){
        return @"110";
    }
    else if( [type isEqualToString:@"紧急不重要"]){
        return @"120";
    }
    else if( [type isEqualToString:@"紧急重要"]){
        return @"130";
    }
    return @"100";
}

+ (NSString *)getTaskTypeString:(NSString *)type
{
    if( [type isEqualToString:@"100"]){
        return @"不紧急不重要";
    }else if( [type isEqualToString:@"110"]){
        return @"不紧急重要";
    }
    else if( [type isEqualToString:@"120"]){
        return @"紧急不重要";
    }
    else if( [type isEqualToString:@"130"]){
        return @"紧急重要";
    }
    return @"不紧急不重要";
}

@end
